#ifndef GAME_FILE_FORMAT_H
#define GAME_FILE_FORMAT_H
#include "game_platform.h"
#include "game_debug_interface.h"

#define HHA_CODE(a, b, c, d) \
    (((uint32)(a) << 0) | ((uint32)(b) << 8) | ((uint32)(c) << 16) | ((uint32)(d) << 24))

#pragma pack(push, 1)
struct hha_header {
#define HHA_MAGIC_VALUE HHA_CODE('h', 'h', 'a', 'f')
    uint32 MagicValue;

#define HHA_VERSION 0
    uint32 Version;

    uint32 TagCount;
    uint32 AssetTypeCount;
    uint32 AssetCount;

    uint64 Tags;        // hha_tag[TagCount]
    uint64 AssetTypes;  // hha_asset_type[AssetTypeCount]
    uint64 Assets;      // hha_asset[AssetCount]
};
struct hha_tag {
    uint32 ID;
    real32 Value;
};
struct hha_asset_type {
    uint32 TypeID;
    uint32 FirstAssetIndex;
    uint32 OnePastLastAssetIndex;
};

enum hha_sound_chain {
    HHASoundChain_None,
    HHASoundChain_Loop,
    HHASoundChain_Advance,
};

struct hha_bitmap {
    uint32 Dim[2];
    real32 AlignPercentage[2];
};

struct hha_sound {
    uint32 ChennelCount;
    uint32 SampleCount;
    // hha_sound_chain Chain;
    uint32 Chain;
};

struct hha_font_glyph {
    uint32 UnicodeCodePoint;
    bitmap_id BitmapID;
};

struct hha_font {
    uint32 OnePastHeighestCodePoint;
    real32 AscenderHeight;
    real32 DescenderHeight;
    real32 ExternalLeading;
    uint32 GlyphCount;
};
struct hha_asset {
    uint64 DataOffset;
    uint32 FirstTagIndex;
    uint32 OnePastLastTagIndex;
    union {
        hha_bitmap Bitmap;
        hha_sound Sound;
        hha_font Font;
    };
};
enum assets_type_id {
    // bitmap
    Asset_None,
    Asset_Shadow,
    Asset_Tree,
    Asset_Sword,
    Asset_Rock,

    Asset_Grass,
    Asset_Tuft,
    Asset_Stone,

    Asset_Head,
    Asset_Cape,
    Asset_Torso,

    Asset_Font,
    Asset_FontGlyph,

    // sounds
    Asset_Bloop,
    Asset_Crack,
    Asset_Drop,
    Asset_Glide,
    Asset_Music,
    Asset_Puhp,

    Asset_OpeningCutscene,
    Asset_Count,
};

enum asset_tag_id {
    Tag_Smoothness,
    Tag_Flatness,
    Tag_FacingDirection,  // NOTE:角度是相对于正右方向的弧度
    Tag_UnicodeCodepoint,

    Tag_FontType,
    Tag_ShotIndex,
    Tag_LayerIndex,
    Tag_Count,
};

enum asset_font_type {
    FontType_Default = 0,
    FontType_Debug = 10,
};

#pragma pack(pop)
#endif